package shuru;
import java.util.*;
import java.io.*;
public class jiage {
	public static void main(String args[]) {
		File file=new File("C:\\Users\\ASUS\\Desktop\\价格 (2).txt");
		Scanner wenjian=null;
		int count=0;
		int sum=0;
		try {
			int price=0;
			wenjian=new Scanner(file);
			wenjian.useDelimiter("[^0123456789.]+");
			while(wenjian.hasNextInt()) {
				price =wenjian.nextInt();
				count++;
				sum=sum+price;
				
				
				System.out.println(price);
			}
			double aver =sum/count;
			String str =String.format("%.3f",aver);
			System.out.println(str);
			try(FileWriter writer=new FileWriter(file,true)){
			writer.write("\n平均价格："+str);
			}
		}
		catch(Exception exp) {
			System.out.println(exp);
		}
		
	}

}
